{include file="header.html"}
<body class="gr">

<div class="navBar">
	<a class="left" href="javascript:history.back()"><i class="return"></i></a>
	<div class="titleView">确认订单</div>
</div>

<form action="wap.php?app=coffee_cart&act=order_pay" method="post">
<div class="cart-jiesuan main-top">
	<ul class="groupView">
		{foreach from=$data.coffees name=g item=g}
		<li class="ge-bottom ge-light">
			<div class="row">
				<div class="right">
					<div class="price">￥{number_format($g->price,2)}</div>
					<div>× {$g->quantity}</div>
				</div>
				<div class="pic" style="background-image:url({$g->default_pic});"></div>
				{$g->name}
			</div>
		</li>
		{/foreach}
	</ul>
	
	<div class="groupView ge-top ge-bottom ge-light">
		<div class="view">
			<div class="name"><tt>{$data.city}</tt>-{$data.shop_name}</div>
			<div class="numView">咖啡送至<span></span>号座位</div>
			<div class="clear"></div>
		</div>
		<div class="view">
			<div class="area desks"></div>
		</div>
	</div>
	
	<div class="groupView ge-top ge-bottom ge-light">
		<div class="view">
			<div class="name">小票留言</div>
			<div class="clear"></div>
		</div>
		<div class="view">
			<div class="area"><textarea name="memo" placeholder="写一段话送过去吧！"></textarea></div>
		</div>
	</div>
	
	<section>
		<ul class="tableView tableView-light tableView-noMargin payMethod">
			<li><h1>支付方式</h1></li>
			<li class="yue">
				<h1>
					<input type="radio" name="pay" id="yue" value="yue" method_name="余额支付" />
					<label for="yue"><em></em>余额支付</label>
				</h1>
			</li>
			<li class="wxpay">
				<h1>
					<input type="radio" name="pay" id="wxpay" value="wxpay_h5" method_name="微信支付" />
					<label for="wxpay"><em></em>微信支付</label>
				</h1>
			</li>
			<!--
			<li class="alipay">
				<h1>
					<input type="radio" name="pay" id="alipay" value="alipay" method_name="支付宝支付" />
					<label for="alipay"><em></em>支付宝支付</label>
				</h1>
			</li>
			-->
		</ul>
	</section>
	
	<div class="bottomView toolBar-black ge-top">
		<a href="javascript:void(0)" class="btn">提交订单</a>
		<div>实付款: <span>￥{number_format($data.total_price,2)}</span></div>
	</div>
</div>

<input type="hidden" name="coffee_shop_id" id="coffee_shop_id" value="{if isset($coffee_shop_id)}{$coffee_shop_id}{/if}" />
<input type="hidden" name="desk" id="desk" value="" />
<input type="hidden" name="coupon" value="" />
<input type="hidden" name="total_price" value="{$data.total_price}" />
<input type="hidden" name="pay_method" id="pay_method" value="" />
<input type="hidden" name="pay_method_name" id="pay_method_name" value="" />
<textarea name="coffees" style="display:none;">{stripslashes($coffees)}</textarea>
</form>
<input type="hidden" id="money" value="{$data.money}" />
<input type="hidden" id="totalprice" value="{$data.total_price}" />

{include file="footer.html"}
<script type="text/javascript" src="js/city.js"></script>
<script>
function changeCityCode(){
	$('tt').each(function(){
		var html = $(this).html();
		if(isNaN(html))return true;
		$(this).html(getCityName(html).replace(/市/g, ''));
	});
}
$(function(){
	changeCityCode();
	$('.right .price, .bottomView span').priceFont('bigPrice');
	$('.payMethod li').click(function(){
		var input = $(this).find('input');
		$('#pay_method').val(input.val());
		$('#pay_method_name').val(input.attr('method_name'));
	});
	if($('#money').val()*1<$('#totalprice').val()*1)$('.yue').hide();
	var desk = Number('{$data.desks}'), desks = $('.desks');
	for(var i=1; i<=desk; i++){
		desks.append('<a href="javascript:void(0)"><span>'+i.fillZero(2)+'</span></a>');
	}
	desks.append('<div class="clear"></div>');
	$('.desks a').click(function(){
		$('.desks a').removeClass('x');
		var num = $(this).addClass('x').text();
		$('#desk').val(num);
		$('.numView span').html(num);
		$('.numView').addClass('x');
	});
	$('.bottomView .btn').click(function(){
		if(!$('#desk').val().length){
			$.overloadError('请选择座位号');
			return;
		}
		if(!$('#pay_method').val()){
			$.overloadError('请选择支付方式');
			return;
		}
		if($('#money').val()*1<=0 && $('#pay_method').val()=='yue'){
			$.overloadError('当前支付余额不足');
			return;
		}
		if($('#money').val()*1>0 && $('#pay_method').val()=='yue'){
			$('form').attr('action', 'api.php?app=coffee_cart&act=order').ajaxsubmit({
				dataType : 'json',
				success : function(json){
					if(json.error!=0){ $.overloadError(json.msg);return }
					location.href = 'wap.php?app=coffee_cart&act=order_complete&order_sn='+json.data.order_sn;
				}
			});
		}else{
			$('form').attr('action', 'wap.php?app=coffee_cart&act=order_pay').submit();
		}
	});
});
</script>